package com.example.com.skills_utf8;

import android.app.Activity;
import android.content.Intent;
import android.hardware.Camera;
import android.view.Surface;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.app.BaseActivity;
import com.app.MyCamera;
import com.app.MyPhotoAlbum;
import com.app.video.MyVideoCameraPreview;
import com.app.voice.MySensor;
import com.lidroid.xutils.db.annotation.Check;
import com.utils.GsonParse;


public class _62ActivitySearchQrcodeLandspace extends BaseActivity {


    FrameLayout layout_content;
    MyVideoCameraPreview camerapreview = new MyVideoCameraPreview();
    MySensor mysensor = new MySensor();
    MyPhotoAlbum myphotoalbum = new MyPhotoAlbum();  // 处理打开相册

    LinearLayout layout_frame;

    CheckBox cb_qrcode_flashlight;
    ImageView iv_album_photo;


    @Override
    public Integer InitLayout() {

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);


        return R.layout.activity__62_activity_search_qrcode;
    }

    @Override
    public void InitView() {
        layout_content = (FrameLayout)findViewById(R.id.layout_content);
        View view = camerapreview.init(activity);
        layout_content.addView(view);

        layout_frame = (LinearLayout)findViewById(R.id.layout_frame);
        cb_qrcode_flashlight = (CheckBox)findViewById(R.id.cb_qrcode_flashlight);
        iv_album_photo = (ImageView)findViewById(R.id.iv_album_photo);



        mysensor.init(activity);
        mysensor.printSupportSensor();
    }

    @Override
    public void InitListener() {

        cb_qrcode_flashlight.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                if (camerapreview.mycamera == null)
                    return;

                // 是否开启闪光灯
                camerapreview.mycamera.enableSplashLight(isChecked);



            }
        });

        iv_album_photo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                myphotoalbum.SetCallback(new MyPhotoAlbum.Callback() {
                    @Override
                    public void OnFinal(String filename) {
                        super.OnFinal(filename);

                        ShowToast(filename);
                    }
                });
                myphotoalbum.start(activity);
            }
        });



    }

    @Override
    public void InitProcess() {


    }

    @Override
    protected void onResume() {
        super.onResume();

        camerapreview.start();
    }

    @Override
    protected void onPause() {
        super.onStop();

        camerapreview.close();
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        myphotoalbum.OnActivityResult(requestCode, resultCode, data);

    }

}


